Skip to content

Feat: add dictionaries as a supported group column type#23187

Open
Rich-T-kid wants to merge 25 commits into
apache:mainfrom
Rich-T-kid:rich-T-kid/dictionary-groupValuesColumn-impl
Open

Feat: add dictionaries as a supported group column type#23187
Rich-T-kid wants to merge 25 commits into
apache:mainfrom
Rich-T-kid:rich-T-kid/dictionary-groupValuesColumn-impl

Conversation

@Rich-T-kid

@Rich-T-kid Rich-T-kid commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

This PR introduces a specialized GroupColumn implementation for dictionary-typed columns inside GroupValuesColumn, allowing dictionary columns to participate in the columnar, vectorized aggregation path instead of the row-based fallback.

The Implementation is only about 175+ lines of code. the remaining LOC is adding extensive test at the GroupColumn trait level as well as testing the GroupValuesColumn GroupValues trait and how it inter-opts with multi-dictionary group by's.

What changes are included in this PR?

  • Adds a DictionaryGroupValueBuilder struct implementing the GroupColumn trait for Dictionary-typed group-by columns, supporting a configurable subset of value types
  • Extends the type-check gate in GroupValuesColumn::try_new (the matches! block) to accept Dictionary(_, value_type) where value_type is already supported.
  • Adds schema-level support so emitted dictionary group key columns round-trip through the output schema correctly
  • removes casting thats done for each dictionary array in emit

Are these changes tested?

yes. a majority of this PR is test

Are there any user-facing changes?

no. this is a pure perf boost for users.

@github-actions github-actions Bot added the physical-plan Changes to the physical-plan crate label Jun 25, 2026
@Rich-T-kid Rich-T-kid force-pushed the rich-T-kid/dictionary-groupValuesColumn-impl branch from 2b60132 to 1ffc7f0 Compare June 30, 2026 20:23
@Rich-T-kid Rich-T-kid force-pushed the rich-T-kid/dictionary-groupValuesColumn-impl branch from 3f7ff57 to e6b6dce Compare July 1, 2026 04:25
@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

@kumarUjjawal could you run the dictionary benchmarks on this PR? Thx

}
}
DataType::Dictionary(key_dt, value_dt) => {
let new_field = Field::new("", *value_dt.clone(), true);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this field is never read again it may be fine to ignore the name field.

should be weary of similar issues to #21765 (comment)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of annoying that make_group_column takes a field instead of a DataType. Maybe we can change that in a follow up PR?

Comment thread datafusion/physical-plan/src/aggregates/group_values/multi_group_by/dictionary.rs Outdated
@Rich-T-kid

Rich-T-kid commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

@kumarUjjawal wanted to bump this 😄

@geoffreyclaude

Copy link
Copy Markdown
Contributor

run benchmark dictionary_group_values

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c4856707692-778-smmmp 6.12.85+ #1 SMP Mon May 11 08:17:35 UTC 2026 aarch64 GNU/Linux

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Comparing rich-T-kid/dictionary-groupValuesColumn-impl (eb41915) to 01bf68c (merge-base) diff using: dictionary_group_values
Results will be posted here when complete


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

group                                                                             HEAD                                   rich-T-kid_dictionary-groupValuesColumn-impl
-----                                                                             ----                                   --------------------------------------------
dict_intern_emit/intern_emit/size_65536_card_1000_null_0.00                       1.15    869.8±5.08µs 71.9 MElem/sec    1.00  756.8±139.44µs 82.6 MElem/sec
dict_intern_emit/intern_emit/size_65536_card_20_null_0.00                         1.22    779.9±5.80µs 80.1 MElem/sec    1.00   636.7±43.49µs 98.2 MElem/sec
dict_intern_emit/intern_emit/size_65536_card_300_null_0.00                        1.17    809.2±5.84µs 77.2 MElem/sec    1.00  692.8±108.32µs 90.2 MElem/sec
dict_intern_emit/intern_emit/size_65536_card_65536_null_0.00                      2.45      6.3±0.01ms 10.0 MElem/sec    1.00      2.6±0.04ms 24.5 MElem/sec
dict_intern_emit/intern_emit/size_65536_card_75_null_0.00                         1.24    800.2±6.35µs 78.1 MElem/sec    1.00    645.5±6.09µs 96.8 MElem/sec
dict_intern_emit/intern_emit/size_8192_card_1000_null_0.00                        1.42    160.1±0.87µs 48.8 MElem/sec    1.00   112.7±15.66µs 69.3 MElem/sec
dict_intern_emit/intern_emit/size_8192_card_20_null_0.00                          1.28    104.0±1.39µs 75.1 MElem/sec    1.00     81.5±0.45µs 95.8 MElem/sec
dict_intern_emit/intern_emit/size_8192_card_300_null_0.00                         1.30    121.2±1.05µs 64.5 MElem/sec    1.00     92.9±9.63µs 84.1 MElem/sec
dict_intern_emit/intern_emit/size_8192_card_75_null_0.00                          1.17    109.7±1.26µs 71.2 MElem/sec    1.00    94.1±13.82µs 83.0 MElem/sec
dict_intern_emit/intern_emit/size_8192_card_8192_null_0.00                        2.66    678.0±2.09µs 11.5 MElem/sec    1.00   255.3±12.37µs 30.6 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_65536_card_1000_null_0.10     1.04      4.4±0.02ms 57.4 MElem/sec    1.00      4.2±0.01ms 59.7 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_65536_card_20_null_0.10       1.02      4.1±0.02ms 60.5 MElem/sec    1.00      4.1±0.01ms 61.5 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_65536_card_300_null_0.10      1.01      4.2±0.02ms 59.2 MElem/sec    1.00      4.2±0.01ms 60.1 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_65536_card_65536_null_0.10    1.54     16.5±0.05ms 15.2 MElem/sec    1.00     10.7±0.06ms 23.4 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_65536_card_75_null_0.10       1.01      4.2±0.02ms 59.3 MElem/sec    1.00      4.2±0.01ms 60.2 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_8192_card_1000_null_0.10      1.13    618.7±3.27µs 50.5 MElem/sec    1.00    549.9±6.40µs 56.8 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_8192_card_20_null_0.10        1.00    512.1±3.06µs 61.0 MElem/sec    1.00    511.2±3.10µs 61.1 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_8192_card_300_null_0.10       1.05    550.0±3.63µs 56.8 MElem/sec    1.00    522.5±2.60µs 59.8 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_8192_card_75_null_0.10        1.02    526.6±2.85µs 59.3 MElem/sec    1.00    515.0±2.45µs 60.7 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_8192_card_8192_null_0.10      1.74   1479.0±6.20µs 21.1 MElem/sec    1.00    847.9±5.26µs 36.9 MElem/sec

Resource Usage

dictionary_group_values — base (merge-base)

Metric Value
Wall time 380.1s
Peak memory 592.6 MiB
Avg memory 94.8 MiB
CPU user 227.9s
CPU sys 14.8s
Peak spill 0 B

dictionary_group_values — branch

Metric Value
Wall time 330.1s
Peak memory 464.6 MiB
Avg memory 67.9 MiB
CPU user 225.8s
CPU sys 19.2s
Peak spill 0 B

File an issue against this benchmark runner

@Rich-T-kid Rich-T-kid force-pushed the rich-T-kid/dictionary-groupValuesColumn-impl branch from eb41915 to 770abfe Compare July 1, 2026 15:30
@Rich-T-kid Rich-T-kid force-pushed the rich-T-kid/dictionary-groupValuesColumn-impl branch from 770abfe to 243a557 Compare July 1, 2026 15:32
@Rich-T-kid Rich-T-kid changed the title [Draft][22715] introduce dictionarys as a supported group column type Feat:[Draft][22715] add dictionaries as a supported group column type Jul 1, 2026
@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

@codex review

@kumarUjjawal

Copy link
Copy Markdown
Contributor

@kumarUjjawal wanted to bump this 😄

@Rich-T-kid Thank you! I have been sick so I won't be available for review. I will probably get back next week.

@Rich-T-kid Rich-T-kid force-pushed the rich-T-kid/dictionary-groupValuesColumn-impl branch from d4ea0f9 to 894a0a6 Compare July 7, 2026 17:32
pub struct DictionaryGroupValuesColumn<K: ArrowDictionaryKeyType + Send + Sync> {
inner: Box<dyn GroupColumn>,
null_array: ArrayRef,
// Mutex is required because `vectorized_equal_to` takes `&self` (GroupColumn trait

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RefCell doesn't work here because its not sync

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::sync::RwLock may also be an option

@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

PR is ready for review 🚀
@geoffreyclaude could you run the benchmarks one more time to verify theres no regressions 🙇

@geoffreyclaude

Copy link
Copy Markdown
Contributor

PR is ready for review 🚀
@geoffreyclaude could you run the benchmarks one more time to verify theres no regressions 🙇

Did you run them yourself locally? What are your results?

@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

PR is ready for review 🚀
@geoffreyclaude could you run the benchmarks one more time to verify theres no regressions 🙇

Did you run them yourself locally? What are your results?

@geoffreyclaude yes. These are the results compared to main
Image 7-7-26 at 2 10 PM (3)
Image 7-7-26 at 2 10 PM
Image 7-7-26 at 2 10 PM (1)
Image 7-7-26 at 2 10 PM (2)

@Rich-T-kid Rich-T-kid marked this pull request as ready for review July 7, 2026 18:11
@geoffreyclaude

Copy link
Copy Markdown
Contributor

run benchmark dictionary_group_values

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c4907084674-898-7668q 6.12.85+ #1 SMP Mon May 11 08:17:35 UTC 2026 aarch64 GNU/Linux

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Comparing rich-T-kid/dictionary-groupValuesColumn-impl (894a0a6) to 01bf68c (merge-base) diff using: dictionary_group_values
Results will be posted here when complete


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

group                                                                             HEAD                                   rich-T-kid_dictionary-groupValuesColumn-impl
-----                                                                             ----                                   --------------------------------------------
dict_intern_emit/intern_emit/size_65536_card_1000_null_0.00                       1.00    869.0±4.52µs 71.9 MElem/sec    1.18   1025.1±8.39µs 61.0 MElem/sec
dict_intern_emit/intern_emit/size_65536_card_20_null_0.00                         1.00    781.1±7.66µs 80.0 MElem/sec    1.14    891.0±6.32µs 70.1 MElem/sec
dict_intern_emit/intern_emit/size_65536_card_300_null_0.00                        1.00    815.4±7.88µs 76.7 MElem/sec    1.16    945.3±6.21µs 66.1 MElem/sec
dict_intern_emit/intern_emit/size_65536_card_65536_null_0.00                      2.49      6.4±0.07ms  9.8 MElem/sec    1.00      2.6±0.09ms 24.4 MElem/sec
dict_intern_emit/intern_emit/size_65536_card_75_null_0.00                         1.00    798.9±8.58µs 78.2 MElem/sec    1.16    929.6±8.21µs 67.2 MElem/sec
dict_intern_emit/intern_emit/size_8192_card_1000_null_0.00                        1.27    160.6±1.25µs 48.6 MElem/sec    1.00    126.3±0.71µs 61.9 MElem/sec
dict_intern_emit/intern_emit/size_8192_card_20_null_0.00                          1.00    104.5±1.15µs 74.8 MElem/sec    1.30  136.2±176.93µs 57.4 MElem/sec
dict_intern_emit/intern_emit/size_8192_card_300_null_0.00                         1.00    123.4±3.12µs 63.3 MElem/sec    1.08    133.5±2.37µs 58.5 MElem/sec
dict_intern_emit/intern_emit/size_8192_card_75_null_0.00                          1.00    110.3±1.33µs 70.9 MElem/sec    1.09    120.0±0.47µs 65.1 MElem/sec
dict_intern_emit/intern_emit/size_8192_card_8192_null_0.00                        2.71    681.6±4.80µs 11.5 MElem/sec    1.00    252.0±9.82µs 31.0 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_65536_card_1000_null_0.10     1.00      4.4±0.02ms 57.3 MElem/sec    1.04      4.5±0.03ms 55.1 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_65536_card_20_null_0.10       1.01      4.2±0.03ms 60.2 MElem/sec    1.00      4.1±0.05ms 60.8 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_65536_card_300_null_0.10      1.00      4.3±0.03ms 58.6 MElem/sec    1.00      4.3±0.03ms 58.5 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_65536_card_65536_null_0.10    1.54     17.9±1.61ms 14.0 MElem/sec    1.00     11.7±0.07ms 21.4 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_65536_card_75_null_0.10       1.01      4.2±0.03ms 58.9 MElem/sec    1.00      4.2±0.02ms 59.6 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_8192_card_1000_null_0.10      1.00    622.8±4.38µs 50.2 MElem/sec    1.05    654.3±1.58µs 47.8 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_8192_card_20_null_0.10        1.01    512.8±3.55µs 60.9 MElem/sec    1.00    509.7±3.27µs 61.3 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_8192_card_300_null_0.10       1.01    549.4±3.43µs 56.9 MElem/sec    1.00    545.2±2.38µs 57.3 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_8192_card_75_null_0.10        1.01    529.2±4.21µs 59.1 MElem/sec    1.00    522.7±2.93µs 59.8 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_8192_card_8192_null_0.10      1.41   1480.2±8.81µs 21.1 MElem/sec    1.00  1046.9±743.13µs 29.9 MElem/sec

Resource Usage

dictionary_group_values — base (merge-base)

Metric Value
Wall time 295.1s
Peak memory 584.0 MiB
Avg memory 127.2 MiB
CPU user 228.7s
CPU sys 15.4s
Peak spill 0 B

dictionary_group_values — branch

Metric Value
Wall time 340.1s
Peak memory 477.1 MiB
Avg memory 64.7 MiB
CPU user 226.2s
CPU sys 16.0s
Peak spill 0 B

File an issue against this benchmark runner

Comment on lines +135 to +151
let unique_lhs_row_count =
lhs_rows.iter().collect::<hashbrown::HashSet<_>>().len();
if unique_lhs_row_count <= rhs_rows.len() / CACHE_USE_THRESHOLD {
let mut comparison_cache = self.key_to_group_cache.lock().unwrap();
for (position, (&lhs_row, &rhs_row)) in
lhs_rows.iter().zip(rhs_rows).enumerate()
{
if !equal_to_results.get_bit(position) {
continue;
}
let dict_key = dict.key(rhs_row);
let is_equal = *comparison_cache
.entry((lhs_row, dict_key))
.or_insert_with(|| match dict_key {
None => self.inner.equal_to(lhs_row, &self.null_array, 0),
Some(key) => self.inner.equal_to(lhs_row, dict_values, key),
});

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is causing more overhead than its saving.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hashset insertions + mutext lock + hashsing two usize's
O(size * hash) O(1) O(~ unqiue values)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the best thing to do here to to avoid any regressions. That means making this implementation a thin wrapper over an inner GroupColumns implementation. a follow up PR can try to optimize the low-cardinality case similar to #21765

@Rich-T-kid Rich-T-kid changed the title Feat:[Draft][22715] add dictionaries as a supported group column type Feat: add dictionaries as a supported group column type Jul 8, 2026
}
}
DataType::Dictionary(key_dt, value_dt) => {
let new_field = Field::new("", *value_dt.clone(), true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of annoying that make_group_column takes a field instead of a DataType. Maybe we can change that in a follow up PR?

// `get_combined` appends the null sentinel as the final element, so any
// null dictionary key maps to that last index.
let combined_with_null_sentinel =
concat(&[dict.values(), self.null_array.as_ref()])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The concat isn't great tbh bc it reallocates the whole array, but I don't see how we can avoid it. Since the benchmarks are good, it's probably fine.

It's unfortunate that keys might be null. Ideally the dict arrives "normalized" where all keys are valid and may point to a null value.

How likely is it that there's null keys? Would it help to see how often .unwrap_or(null_sentinel_index) happens? If it happens 0 times, we can avoid concat?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The concat isn't great tbh bc it reallocates the whole array, but I don't see how we can avoid it. Since the benchmarks are good, it's probably fine.

I agree, for a 8192 size batch of keys with just a single null value it will cause the entire 8192 batch to be copied to a new array just to append 1 null at the end. Invectorized_append() we can avoid copying value arrays blindly by doing a Arc::ptr_eq() check. this is a cheap comparison that can save an O(target_batch_size) + 1 copy for every call. as for vectorized_equal_to() theres not much we can do here since it takes a &self meaning we wouldn't be able to re-cache the values array.

It's unfortunate that keys might be null. Ideally the dict arrives "normalized" where all keys are valid and may point to a null value.
How likely is it that there's null keys? Would it help to see how often .unwrap_or(null_sentinel_index) happens? If it happens 0 times, we can avoid concat?

This is what I tried avoiding by adding the null branch case. Fundemantally we have to account for the possibility of keys being null.
arrows format doc:

The memory layout for a dictionary-encoded array is the same as that of a primitive integer layout.

the primitive array section states:

A primitive value array represents an array of values each having the same physical slot width typically measured in bytes, though the spec also provides for bit-packed types (e.g. boolean values encoded in bits).

Internally, the array contains a contiguous memory buffer whose total size is at least as large as the slot width multiplied by the array length. For bit-packed types, the size is rounded up to the nearest byte.
The associated validity bitmap is contiguously allocated (as described above) but does not need to be adjacent in memory to the values buffer.
Example Layout: Int32 Array
For example a primitive array of int32s:
[1, null, 2, 4, 8]

Unlike a primitive, where nulls live in a single validity bitmap, a dictionary array's logical nulls can come from two independent places: the keys array's validity bitmap, or a null entry in the values (dictionary) array that a key points to. The field's nullable flag doesn't tell us which it's only an advisory "may contain nulls," same as for any type. So to know the actual null situation we have to inspect both the keys and the values arrays.

@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

Kind of annoying that make_group_column takes a field instead of a DataType. Maybe we can change that in a follow up PR?

@jayshrivastava make_group_column() needs to take in a field because primitives can optimize storage if they know for certain no nulls will exist in the input.

primitive.rs says :

/// Optimized to skip null buffer construction if the input is known to be non nullable

@Rich-T-kid Rich-T-kid force-pushed the rich-T-kid/dictionary-groupValuesColumn-impl branch from 1f4816e to e2e79ba Compare July 9, 2026 16:18
@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

@jayshrivastava I pushed a revision could you take another look?

@jayshrivastava

jayshrivastava commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

@Rich-T-kid Your optimization relies on the pointer being the same, generally, what are the odds of that? I suggested earlier to count how many times .unwrap_or(null_sentinel_index) is used and if theres no null keys, skip the concat. Is that more or less likely?

One way to find out is to run the benches and print out how many times each of those things happen, assuming there's enough interesting cases in the benches.

Pointer checking is a bit of a smell. We used to do it in dynamic filtering to check if two filters are the same but everyone disliked that. We have since moved away from pointer equality checking.

@jayshrivastava

Copy link
Copy Markdown
Contributor

@Rich-T-kid

Also, if there is already a null value in the values array, then we don't need to append a sentinel.

Avoiding concat if there's no null keys or if there's already a null value might be good enough. It could avoid concating more than the pointer check.

@Rich-T-kid

Rich-T-kid commented Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Also, if there is already a null value in the values array, then we don't need to append a sentinel.
Avoiding concat if there's no null keys or if there's already a null value might be good enough. It could avoid concating more than the pointer check.

This make sense. updating the PR 👍

@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

Your optimization relies on the pointer being the same, generally, what are the odds of that?
Im not sure of the exact number, in #21765 the e2e benchmarks showed a a large re-use in the values ptr because slicing a dictionary clones the value ptr.

I suggested earlier to count how many times .unwrap_or(null_sentinel_index) is used and if theres no null keys, skip the concat. Is that more or less likely?
One way to find out is to run the benches and print out how many times each of those things happen, assuming there's enough interesting cases in the benches.

in the benchmarks the null rate is set to 0% and 10%. in the case where there are no nulls in the current batch there is no concat operation. the alternative to using concat is to use a non-vectorized approach.
Example

 // Null keys but values has no null entry: scalar fallback per row.
            for &row_index in rows {
                match dict.key(row_index) {
                    None => self.inner.append_val(&self.null_array, 0)?,
                    Some(key) => self.inner.append_val(dict.values(), key)?,
                }
            }

Pointer checking is a bit of a smell. We used to do it in dynamic filtering to check if two filters are the same but everyone disliked that. We have since moved away from pointer equality checking.

make sense, Ive removed the pointer check, as well as the concat call.

@Rich-T-kid

Copy link
Copy Markdown
Contributor Author

I believe this PR is ready for a maintainer to take a look 👍

@kumarUjjawal

Copy link
Copy Markdown
Contributor

run benchmark dictionary_group_values

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark running (GKE) | trigger
Instance: c4a-highmem-16 (12 vCPU / 65 GiB) | Linux bench-c4932335413-956-nj84w 6.12.85+ #1 SMP Mon May 11 08:17:35 UTC 2026 aarch64 GNU/Linux

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected

Comparing rich-T-kid/dictionary-groupValuesColumn-impl (fb7856f) to 01bf68c (merge-base) diff using: dictionary_group_values
Results will be posted here when complete


File an issue against this benchmark runner

@adriangbot

Copy link
Copy Markdown

🤖 Benchmark completed (GKE) | trigger

Instance: c4a-highmem-16 (12 vCPU / 65 GiB)

CPU Details (lscpu)
Architecture:                            aarch64
CPU op-mode(s):                          64-bit
Byte Order:                              Little Endian
CPU(s):                                  16
On-line CPU(s) list:                     0-15
Vendor ID:                               ARM
Model name:                              Neoverse-V2
Model:                                   1
Thread(s) per core:                      1
Core(s) per cluster:                     16
Socket(s):                               -
Cluster(s):                              1
Stepping:                                r0p1
BogoMIPS:                                2000.00
Flags:                                   fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh rng bti
L1d cache:                               1 MiB (16 instances)
L1i cache:                               1 MiB (16 instances)
L2 cache:                                32 MiB (16 instances)
L3 cache:                                80 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Not affected
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      Not affected
Vulnerability Spec store bypass:         Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:                Mitigation; __user pointer sanitization
Vulnerability Spectre v2:                Mitigation; CSV2, BHB
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Not affected
Details

group                                                                             HEAD                                   rich-T-kid_dictionary-groupValuesColumn-impl
-----                                                                             ----                                   --------------------------------------------
dict_intern_emit/intern_emit/size_65536_card_1000_null_0.00                       1.10    876.4±8.31µs 71.3 MElem/sec    1.00  798.0±163.57µs 78.3 MElem/sec
dict_intern_emit/intern_emit/size_65536_card_20_null_0.00                         1.12    789.8±8.45µs 79.1 MElem/sec    1.00  704.8±118.38µs 88.7 MElem/sec
dict_intern_emit/intern_emit/size_65536_card_300_null_0.00                        1.08    812.8±8.52µs 76.9 MElem/sec    1.00  749.2±144.67µs 83.4 MElem/sec
dict_intern_emit/intern_emit/size_65536_card_65536_null_0.00                      2.44      6.3±0.02ms  9.9 MElem/sec    1.00      2.6±0.05ms 24.1 MElem/sec
dict_intern_emit/intern_emit/size_65536_card_75_null_0.00                         1.21    804.9±9.11µs 77.6 MElem/sec    1.00    667.8±7.33µs 93.6 MElem/sec
dict_intern_emit/intern_emit/size_8192_card_1000_null_0.00                        1.32    163.6±2.46µs 47.7 MElem/sec    1.00   123.9±28.16µs 63.1 MElem/sec
dict_intern_emit/intern_emit/size_8192_card_20_null_0.00                          1.24    106.6±2.45µs 73.3 MElem/sec    1.00     85.9±2.05µs 90.9 MElem/sec
dict_intern_emit/intern_emit/size_8192_card_300_null_0.00                         1.29    124.6±1.96µs 62.7 MElem/sec    1.00     96.4±6.80µs 81.1 MElem/sec
dict_intern_emit/intern_emit/size_8192_card_75_null_0.00                          1.13    112.6±1.61µs 69.4 MElem/sec    1.00    99.5±16.83µs 78.5 MElem/sec
dict_intern_emit/intern_emit/size_8192_card_8192_null_0.00                        2.57    683.5±3.28µs 11.4 MElem/sec    1.00   265.7±26.89µs 29.4 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_65536_card_1000_null_0.10     1.07      4.4±0.02ms 56.9 MElem/sec    1.00      4.1±0.01ms 60.8 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_65536_card_20_null_0.10       1.03      4.2±0.03ms 59.8 MElem/sec    1.00      4.0±0.02ms 61.8 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_65536_card_300_null_0.10      1.04      4.3±0.03ms 58.6 MElem/sec    1.00      4.1±0.01ms 61.0 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_65536_card_65536_null_0.10    1.40     18.7±1.03ms 13.4 MElem/sec    1.00     13.4±0.65ms 18.7 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_65536_card_75_null_0.10       1.04      4.3±0.03ms 58.7 MElem/sec    1.00      4.1±0.06ms 61.2 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_8192_card_1000_null_0.10      1.16    623.8±3.55µs 50.1 MElem/sec    1.00    539.8±2.75µs 57.9 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_8192_card_20_null_0.10        1.03    515.0±3.80µs 60.7 MElem/sec    1.00    498.5±4.00µs 62.7 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_8192_card_300_null_0.10       1.07    552.0±3.58µs 56.6 MElem/sec    1.00    515.0±3.30µs 60.7 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_8192_card_75_null_0.10        1.05    534.0±3.74µs 58.5 MElem/sec    1.00    507.7±3.13µs 61.5 MElem/sec
dict_repeated_intern_emit/repeated_intern_emit/size_8192_card_8192_null_0.10      1.76   1486.4±8.77µs 21.0 MElem/sec    1.00    844.0±3.58µs 37.0 MElem/sec

Resource Usage

dictionary_group_values — base (merge-base)

Metric Value
Wall time 475.1s
Peak memory 590.0 MiB
Avg memory 77.7 MiB
CPU user 230.9s
CPU sys 15.5s
Peak spill 0 B

dictionary_group_values — branch

Metric Value
Wall time 465.1s
Peak memory 512.6 MiB
Avg memory 48.3 MiB
CPU user 222.1s
CPU sys 22.6s
Peak spill 0 B

File an issue against this benchmark runner

}
}

fn into_dict(values: ArrayRef) -> ArrayRef {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The emitted DictionaryArray uses identity keys (key[i] = i), so output is fully expanded with no value sharing. Could you add a short doc-comment explaining this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

valid_bounds is guarded with assert! which panics. A Dictionary(Int8, Utf8) column with >127 distinct groups would cause a panic in production rather than a graceful error. All other error paths here use Result. converting into_dict to -> Result and returning internal_err! on overflow, or checking bounds at intern time so build / take_n stay infallible.

&value_indices,
equal_to_results,
);
} else if let Some(sentinel) = Self::null_sentinel_index(dict_values) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a null key in rhs_rows is mapped to sentinel_idx inside dict_values (the batch's values array), and then passed to self.inner.vectorized_equal_to . But the null that was originally appended went through self.inner.append_val(&self.null_array, 0), a null from a different array than this batch's dict_values .

Can you confirm that all inner builder implementations (bytes, primitive, etc.) short-circuit on null equality before reading the array content so comparing "null from null_array " vs "null from dict_values [sentinel]" always returns true ?

Arc::new(DictionaryArray::<K>::new(keys, values))
}

/// Returns the index of the first null in `values`, or `None` if there are no nulls.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use use bit-level null iteration?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-plan Changes to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants